package dynamicController

import (
	"github.com/savsgio/atreugo/v11"
	"hotter/dynamicService"
	"hotter/variable"
	"strings"
)

type DynamicController struct {
	DynamicService *dynamicService.DynamicService
}

func NewDynamicController() *DynamicController {
	return &DynamicController{
		DynamicService: dynamicService.NewDynamicService(),
	}
}

func (dc *DynamicController) GetCatalogueInfoByLevel(ctx *atreugo.RequestCtx) error {
	path := strings.Split(string(ctx.Path()), "file")[1]
	return ctx.JSONResponse(dc.DynamicService.GetFilesByLevel(variable.Path + path))
}

func (dc *DynamicController) GetCatalogueInfoByLevelAsync(ctx *atreugo.RequestCtx) error {
	path := strings.Split(string(ctx.Path()), "fileAsync")[1]
	return ctx.JSONResponse(dc.DynamicService.GetFilesByLevelAsync(variable.Path + path))
}
